<!DOCTYPE html>
<html>
<head>
  <title>SingleQueryResult.java</title>
  <meta http-equiv='Content-Type' content='text/html; charset=UTF-8'/>
  <link rel='stylesheet' type='text/css' href='../../../../../coverage.css'/>
  <link rel='shortcut icon' type='image/png' href='../../../../../logo.png'/>
  <script type='text/javascript' src='../../../../../coverage.js'></script>
  <script type='text/javascript' src='../../../../../prettify.js'></script>
</head>
<body onload='prettyPrint()'>
  <table cellpadding='0' cellspacing='1'>
    <caption>igraph_client_java/src/main/java/com/taobao/igraph/client/model/SingleQueryResult.java</caption>
    <tr>
      <td class='line'>1</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>package com.taobao.igraph.client.core.model;</pre></td>
    </tr>
    <tr><td class='line'></td><td colspan='2'>&nbsp;</td></tr>
    <tr>
      <td class='line'></td><td>&nbsp;</td>
      <td><pre class='imports prettyprint' onclick='showHideLines(this)'><div>import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.io.Serializable;

import lombok.NonNull;

import com.google.protobuf.ByteString;
import com.taobao.igraph.client.proto.PGQueryResultProtocol;
import com.taobao.igraph.client.proto.PGQueryResultProtocol.MatchRecords;
</div><span>import ...</span></pre></td>
    </tr>
    <tr><td class='line'></td><td colspan='2'>&nbsp;</td></tr>
    <tr>
      <td class='line'>15</td><td class='count'>1</td>
      <td><pre class='prettyprint covered' id='l15s0'>public class SingleQueryResult implements Serializable {</pre></td>
    </tr>
    <tr>
      <td class='line'>16</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>    private static final long serialVersionUID = 1L;</pre></td>
    </tr>
    <tr>
      <td class='line'>17</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>    private MatchRecords pbMatchRecords;</pre></td>
    </tr>
    <tr>
      <td class='line'>18</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>    private List&lt;MatchRecord> matchRecords;</pre></td>
    </tr>
    <tr>
      <td class='line'>19</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>    private List&lt;String> fieldNames;</pre></td>
    </tr>
    <tr>
      <td class='line'>20</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>    private Map&lt;String, Integer> fieldName2IndexMap;</pre></td>
    </tr>
    <tr>
      <td class='line'>21</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>    private boolean hasError;</pre></td>
    </tr>
    <tr>
      <td class='line'>22</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>    private String errorMsg;</pre></td>
    </tr>
    <tr>
      <td class='line'>23</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>    private List&lt;Map&lt;String, String>> rows;</pre></td>
    </tr>
    <tr><td class='line'></td><td colspan='2'>&nbsp;</td></tr>
    <tr>
      <td class='line'>25</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>    private static List&lt;Map&lt;String, String>> convertMatchRecords(MatchRecords records) {</pre></td>
    </tr>
    <tr>
      <td class='line'>26</td><td class='count'>0</td>
      <td><pre class='prettyprint uncovered' id='l26s0'>        List&lt;Map&lt;String, String>> rows = new ArrayList&lt;Map&lt;String, String>>();</pre></td>
    </tr>
    <tr>
      <td class='line'>27</td><td class='count'>0</td>
      <td><pre class='prettyprint uncovered' id='l27s0'>        List&lt;String> fieldNameList = records.getFieldNameList();</pre></td>
    </tr>
    <tr>
      <td class='line'>28</td><td class='count'>0</td>
      <td><pre class='prettyprint uncovered' id='l28s0'>        int size = fieldNameList.size();</pre></td>
    </tr>
    <tr>
      <td class='line'>29</td><td class='count'>0</td>
      <td><pre class='prettyprint uncovered' id='l29s0'>        List&lt;PGQueryResultProtocol.MatchRecord> recordArrayList = records.getRecordArrayList();</pre></td>
    </tr>
    <tr>
      <td class='line'>30</td><td class='count'>0</td>
      <td><pre class='prettyprint jmp'>        <span id='l30s0' title='Executions: 0' class='uncovered'>for (PGQueryResultProtocol.MatchRecord matchRecord</span> : <span id='l30s1' title='Executions: 0' class='uncovered'>recordArrayList)</span> {</pre></td>
    </tr>
    <tr>
      <td class='line'>31</td><td class='count'>0</td>
      <td><pre class='prettyprint uncovered' id='l31s0'>            Map&lt;String, String> row = new HashMap&lt;String, String>(size);</pre></td>
    </tr>
    <tr>
      <td class='line'>32</td><td class='count'>0</td>
      <td><pre class='prettyprint uncovered' id='l32s0'>            rows.add(row);</pre></td>
    </tr>
    <tr>
      <td class='line'>33</td><td class='count'>0</td>
      <td><pre class='prettyprint uncovered' id='l33s0'>            List&lt;ByteString> fieldValueList = matchRecord.getFieldValueList();</pre></td>
    </tr>
    <tr>
      <td class='line'>34</td><td class='count'>0</td>
      <td><pre class='prettyprint jmp'>            <span id='l34s0' title='Executions: 0' class='uncovered'>for (int i = 0</span>; i &lt; size; i++) {</pre></td>
    </tr>
    <tr>
      <td class='line'>35</td><td class='count'>0</td>
      <td><pre class='prettyprint uncovered' id='l35s0'>                row.put(fieldNameList.get(i), fieldValueList.get(i).toStringUtf8());</pre></td>
    </tr>
    <tr>
      <td class='line'>36</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>            }</pre></td>
    </tr>
    <tr>
      <td class='line'>37</td><td class='count'>0</td>
      <td><pre class='prettyprint uncovered' id='l37s0'>        }</pre></td>
    </tr>
    <tr>
      <td class='line'>38</td><td class='count'>0</td>
      <td><pre class='prettyprint uncovered' id='l38s0'>        return rows;</pre></td>
    </tr>
    <tr>
      <td class='line'>39</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>    }</pre></td>
    </tr>
    <tr><td class='line'></td><td colspan='2'>&nbsp;</td></tr>
    <tr>
      <td class='line'></td><td>&nbsp;</td>
      <td class='comment' onclick='showHideLines(this)'><div>    /**
     * 获取请求的结果内容&lt;br/>
     * List中每一行map结构对应于一行记录，即一个MatchRecord
     * 
     * @return 这次请求的结果
     * @Deprecated use {@link #getMatchRecords()} and {@link #getMatchRecord(int)} instead
     */</div><span>    /*...*/</span></td>
    </tr>
    <tr>
      <td class='line'>48</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>    @Deprecated</pre></td>
    </tr>
    <tr>
      <td class='line'>49</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>    public List&lt;Map&lt;String, String>> getResultRows() {</pre></td>
    </tr>
    <tr>
      <td class='line'>50</td><td class='count'>0</td>
      <td><pre class='prettyprint jmp'>        <span id='l50s0' title='Executions: 0' class='uncovered'>if (rows == null</span> && <span id='l50s1' title='Executions: 0' class='uncovered'>pbMatchRecords != null)</span> {</pre></td>
    </tr>
    <tr>
      <td class='line'>51</td><td class='count'>0</td>
      <td><pre class='prettyprint uncovered' id='l51s0'>            rows = convertMatchRecords(pbMatchRecords);</pre></td>
    </tr>
    <tr>
      <td class='line'>52</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>        }</pre></td>
    </tr>
    <tr>
      <td class='line'>53</td><td class='count'>0</td>
      <td><pre class='prettyprint uncovered' id='l53s0'>        return rows;</pre></td>
    </tr>
    <tr>
      <td class='line'>54</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>    }</pre></td>
    </tr>
    <tr><td class='line'></td><td colspan='2'>&nbsp;</td></tr>
    <tr>
      <td class='line'></td><td>&nbsp;</td>
      <td class='comment' onclick='showHideLines(this)'><div>    /**
     * @return Result中包含错误信息时，返回true
     */</div><span>    /*...*/</span></td>
    </tr>
    <tr>
      <td class='line'>59</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>    public boolean hasError() {</pre></td>
    </tr>
    <tr>
      <td class='line'>60</td><td class='count'>1</td>
      <td><pre class='prettyprint covered' id='l60s0'>        return hasError;</pre></td>
    </tr>
    <tr>
      <td class='line'>61</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>    }</pre></td>
    </tr>
    <tr><td class='line'></td><td colspan='2'>&nbsp;</td></tr>
    <tr>
      <td class='line'>63</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>    public void setHasError(boolean hasError) {</pre></td>
    </tr>
    <tr>
      <td class='line'>64</td><td class='count'>0</td>
      <td><pre class='prettyprint uncovered' id='l64s0'>        this.hasError = hasError;</pre></td>
    </tr>
    <tr>
      <td class='line'>65</td><td class='count'>0</td>
      <td><pre class='prettyprint uncovered' id='l65s0'>    }</pre></td>
    </tr>
    <tr><td class='line'></td><td colspan='2'>&nbsp;</td></tr>
    <tr>
      <td class='line'>67</td><td>&nbsp;</td>
      <td><pre class='comment'>    /** @return 错误信息 **/</pre></td>
    </tr>
    <tr>
      <td class='line'>68</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>    public String getErrorMsg() {</pre></td>
    </tr>
    <tr>
      <td class='line'>69</td><td class='count'>1</td>
      <td><pre class='prettyprint covered' id='l69s0'>        return errorMsg;</pre></td>
    </tr>
    <tr>
      <td class='line'>70</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>    }</pre></td>
    </tr>
    <tr><td class='line'></td><td colspan='2'>&nbsp;</td></tr>
    <tr>
      <td class='line'>72</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>    public void setErrorMsg(String errorMsg) {</pre></td>
    </tr>
    <tr>
      <td class='line'>73</td><td class='count'>0</td>
      <td><pre class='prettyprint uncovered' id='l73s0'>        this.errorMsg = errorMsg;</pre></td>
    </tr>
    <tr>
      <td class='line'>74</td><td class='count'>0</td>
      <td><pre class='prettyprint uncovered' id='l74s0'>    }</pre></td>
    </tr>
    <tr><td class='line'></td><td colspan='2'>&nbsp;</td></tr>
    <tr>
      <td class='line'>76</td><td>&nbsp;</td>
      <td><pre class='comment'>    /** @return 结果的所有字段名 **/</pre></td>
    </tr>
    <tr>
      <td class='line'>77</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>    public List&lt;String> getFieldNames() {</pre></td>
    </tr>
    <tr>
      <td class='line'>78</td><td class='count'>0</td>
      <td><pre class='prettyprint uncovered' id='l78s0'>        return fieldNames;</pre></td>
    </tr>
    <tr>
      <td class='line'>79</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>    }</pre></td>
    </tr>
    <tr><td class='line'></td><td colspan='2'>&nbsp;</td></tr>
    <tr>
      <td class='line'></td><td>&nbsp;</td>
      <td class='comment' onclick='showHideLines(this)'><div>    /**
     * 检索给定字段的在MatchRecord的位置
     *
     * @param fieldName
     *            给定的检索字段名
     * @return 若字段存在，返回字段位置(0 ~ getFieldNames().size()-1)；否则，返回负值
     */</div><span>    /*...*/</span></td>
    </tr>
    <tr>
      <td class='line'>88</td><td class='count'>0</td>
      <td><pre class='prettyprint jmp'>    <span id='l88s0' title='Executions: 0' class='uncovered'>public int getFieldIndex(@NonNull String fieldName) {</span></pre></td>
    </tr>
    <tr>
      <td class='line'>89</td><td class='count'>0</td>
      <td><pre class='prettyprint jmp'>        <span id='l89s0' title='Executions: 0' class='uncovered'>if (fieldName2IndexMap == null)</span> {</pre></td>
    </tr>
    <tr>
      <td class='line'>90</td><td class='count'>0</td>
      <td><pre class='prettyprint uncovered' id='l90s0'>            return -1;</pre></td>
    </tr>
    <tr>
      <td class='line'>91</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>        }</pre></td>
    </tr>
    <tr>
      <td class='line'>92</td><td class='count'>0</td>
      <td><pre class='prettyprint uncovered' id='l92s0'>        Integer index = fieldName2IndexMap.get(fieldName);</pre></td>
    </tr>
    <tr>
      <td class='line'>93</td><td class='count'>0</td>
      <td><pre class='prettyprint jmp'>        <span id='l93s0' title='Executions: 0' class='uncovered'>if (index == null)</span> {</pre></td>
    </tr>
    <tr>
      <td class='line'>94</td><td class='count'>0</td>
      <td><pre class='prettyprint uncovered' id='l94s0'>            return -1;</pre></td>
    </tr>
    <tr>
      <td class='line'>95</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>        }</pre></td>
    </tr>
    <tr>
      <td class='line'>96</td><td class='count'>0</td>
      <td><pre class='prettyprint uncovered' id='l96s0'>        return index;</pre></td>
    </tr>
    <tr>
      <td class='line'>97</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>    }</pre></td>
    </tr>
    <tr><td class='line'></td><td colspan='2'>&nbsp;</td></tr>
    <tr>
      <td class='line'></td><td>&nbsp;</td>
      <td class='comment' onclick='showHideLines(this)'><div>    /**
     * @return 结果集的大小，即MatchRecord的数量
     */</div><span>    /*...*/</span></td>
    </tr>
    <tr>
      <td class='line'>102</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>    public int size() {</pre></td>
    </tr>
    <tr>
      <td class='line'>103</td><td class='count'>0</td>
      <td><pre class='prettyprint jmp'>        <span id='l103s0' title='Executions: 0' class='uncovered'>if (matchRecords == null)</span> {</pre></td>
    </tr>
    <tr>
      <td class='line'>104</td><td class='count'>0</td>
      <td><pre class='prettyprint uncovered' id='l104s0'>            return 0;</pre></td>
    </tr>
    <tr>
      <td class='line'>105</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>        }</pre></td>
    </tr>
    <tr>
      <td class='line'>106</td><td class='count'>0</td>
      <td><pre class='prettyprint uncovered' id='l106s0'>        return matchRecords.size();</pre></td>
    </tr>
    <tr>
      <td class='line'>107</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>    }</pre></td>
    </tr>
    <tr><td class='line'></td><td colspan='2'>&nbsp;</td></tr>
    <tr>
      <td class='line'>109</td><td>&nbsp;</td>
      <td><pre class='comment'>    /** @return Size() == 0 **/</pre></td>
    </tr>
    <tr>
      <td class='line'>110</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>    public boolean empty() {</pre></td>
    </tr>
    <tr>
      <td class='line'>111</td><td class='count'>0</td>
      <td><pre class='prettyprint jmp'>        <span id='l111s0' title='Executions: 0' class='uncovered'>return size() == 0;</span></pre></td>
    </tr>
    <tr>
      <td class='line'>112</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>    }</pre></td>
    </tr>
    <tr><td class='line'></td><td colspan='2'>&nbsp;</td></tr>
    <tr>
      <td class='line'></td><td>&nbsp;</td>
      <td class='comment' onclick='showHideLines(this)'><div>    /**
     * 获取结果集中其中一条记录
     *
     * @param index
     *            所要获取记录的序号
     * @return 若记录存在，则返回该记录；否则返回null
     */</div><span>    /*...*/</span></td>
    </tr>
    <tr>
      <td class='line'>121</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>    public MatchRecord getMatchRecord(int index) {</pre></td>
    </tr>
    <tr>
      <td class='line'>122</td><td class='count'>0</td>
      <td><pre class='prettyprint jmp'>        <span id='l122s0' title='Executions: 0' class='uncovered'>if (matchRecords == null</span> || <span id='l122s1' title='Executions: 0' class='uncovered'>index &lt; 0</span> || <span id='l122s2' title='Executions: 0' class='uncovered'>index >= matchRecords.size())</span> {</pre></td>
    </tr>
    <tr>
      <td class='line'>123</td><td class='count'>0</td>
      <td><pre class='prettyprint uncovered' id='l123s0'>            return null;</pre></td>
    </tr>
    <tr>
      <td class='line'>124</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>        }</pre></td>
    </tr>
    <tr>
      <td class='line'>125</td><td class='count'>0</td>
      <td><pre class='prettyprint uncovered' id='l125s0'>        return matchRecords.get(index);</pre></td>
    </tr>
    <tr>
      <td class='line'>126</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>    }</pre></td>
    </tr>
    <tr><td class='line'></td><td colspan='2'>&nbsp;</td></tr>
    <tr>
      <td class='line'></td><td>&nbsp;</td>
      <td class='comment' onclick='showHideLines(this)'><div>    /**
     * @return 获取结果集中的所有记录
     */</div><span>    /*...*/</span></td>
    </tr>
    <tr>
      <td class='line'>131</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>    public List&lt;MatchRecord> getMatchRecords() {</pre></td>
    </tr>
    <tr>
      <td class='line'>132</td><td class='count'>1</td>
      <td><pre class='prettyprint covered' id='l132s0'>        return matchRecords;</pre></td>
    </tr>
    <tr>
      <td class='line'>133</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>    }</pre></td>
    </tr>
    <tr><td class='line'></td><td colspan='2'>&nbsp;</td></tr>
    <tr>
      <td class='line'>135</td><td class='count'>1</td>
      <td><pre class='prettyprint jmp'>    <span id='l135s0' title='Executions: 1' class='covered'>public void setResult(@NonNull MatchRecords pbMatchRecords) {</span></pre></td>
    </tr>
    <tr>
      <td class='line'>136</td><td class='count'>1</td>
      <td><pre class='prettyprint covered' id='l136s0'>        this.pbMatchRecords = pbMatchRecords;</pre></td>
    </tr>
    <tr>
      <td class='line'>137</td><td class='count'>1</td>
      <td><pre class='prettyprint covered' id='l137s0'>        decode(pbMatchRecords);</pre></td>
    </tr>
    <tr>
      <td class='line'>138</td><td class='count'>1</td>
      <td><pre class='prettyprint covered' id='l138s0'>    }</pre></td>
    </tr>
    <tr><td class='line'></td><td colspan='2'>&nbsp;</td></tr>
    <tr>
      <td class='line'>140</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>    private void decode(MatchRecords pbMatchRecords) {</pre></td>
    </tr>
    <tr>
      <td class='line'>141</td><td class='count'>1</td>
      <td><pre class='prettyprint covered' id='l141s0'>        fieldNames = pbMatchRecords.getFieldNameList();</pre></td>
    </tr>
    <tr>
      <td class='line'>142</td><td class='count'>1</td>
      <td><pre class='prettyprint covered' id='l142s0'>        fieldName2IndexMap = new HashMap&lt;String, Integer>();</pre></td>
    </tr>
    <tr>
      <td class='line'>143</td><td class='count'>1</td>
      <td><pre class='prettyprint covered' id='l143s0'>        int index = 0;</pre></td>
    </tr>
    <tr>
      <td class='line'>144</td><td class='count'>1</td>
      <td><pre class='prettyprint jmp'>        <span id='l144s0' title='Executions: 1' class='covered'>for (String fieldName</span> : <span id='l144s1' title='Executions: 8' class='covered'>fieldNames)</span> {</pre></td>
    </tr>
    <tr>
      <td class='line'>145</td><td class='count'>8</td>
      <td><pre class='prettyprint covered' id='l145s0'>            fieldName2IndexMap.put(fieldName, index);</pre></td>
    </tr>
    <tr>
      <td class='line'>146</td><td class='count'>8</td>
      <td><pre class='prettyprint covered' id='l146s0'>            index++;</pre></td>
    </tr>
    <tr>
      <td class='line'>147</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>        }</pre></td>
    </tr>
    <tr><td class='line'></td><td colspan='2'>&nbsp;</td></tr>
    <tr>
      <td class='line'>149</td><td class='count'>1</td>
      <td><pre class='prettyprint covered' id='l149s0'>        matchRecords = new ArrayList&lt;MatchRecord>();</pre></td>
    </tr>
    <tr>
      <td class='line'>150</td><td class='count'>1</td>
      <td><pre class='prettyprint jmp'>        <span id='l150s0' title='Executions: 1' class='covered'>for (PGQueryResultProtocol.MatchRecord pbMatchRecord</span> : <span id='l150s1' title='Executions: 1' class='covered'>pbMatchRecords.getRecordArrayList())</span> {</pre></td>
    </tr>
    <tr>
      <td class='line'>151</td><td class='count'>1</td>
      <td><pre class='prettyprint covered' id='l151s0'>            matchRecords.add(new MatchRecord(pbMatchRecord, fieldName2IndexMap));</pre></td>
    </tr>
    <tr>
      <td class='line'>152</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>        }</pre></td>
    </tr>
    <tr>
      <td class='line'>153</td><td class='count'>1</td>
      <td><pre class='prettyprint covered' id='l153s0'>    }</pre></td>
    </tr>
    <tr>
      <td class='line'>154</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>}</pre></td>
    </tr>
  </table>
</body>
</html>
